package com.scalar.chiptrack.commons.bean;

import com.scalar.chiptrack.commons.Constants;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.ArrayList;
import java.util.Iterator;

/**
  * User: Ganesh
  * Date: Apr 29, 2008
  * Time: 11:25:58 AM
 */

public class TableMetaDataBean implements Serializable
{
    private String mDisplayType = "";
    private String mTableName = "";
    private String mSortOrder = null;
    private String mSortColumn = null;

    private LinkedHashMap mColumnMap = null;

    public TableMetaDataBean()
    {
        mDisplayType = "";
        mTableName = "";
        mColumnMap = new LinkedHashMap();
        mSortOrder = Constants.SORT_ORDER_ASCE;
        mSortColumn = "";
    }

    public void addColumnDetailsList( ArrayList resultMetaDataBeanList )
    {
        ResultMetaDataBean resultMetaDataBean = null;
        mColumnMap = new LinkedHashMap();
        for ( int i = 0; i < resultMetaDataBeanList.size(); i++ )
        {
            resultMetaDataBean = ( ResultMetaDataBean ) resultMetaDataBeanList.get( i );
            mColumnMap.put( resultMetaDataBean.getColumnName(), resultMetaDataBean );
        }
    }
    /**
     * Returns the details of all the columns present in this table meta data. The second
     * parameter has to be passed as true to return the details of only those columns
     * which have to be displayed
     */
    public ArrayList getColumnDetailsList( boolean tobeDisplayedOnly )
    {
        ArrayList resultMetaDataBeanList = new ArrayList();
        ResultMetaDataBean resultMetaDataBean = null;
        Iterator iterator = mColumnMap.values().iterator();
        while ( iterator.hasNext() )
        {
            resultMetaDataBean = ( ResultMetaDataBean ) iterator.next();
            if ( tobeDisplayedOnly == true )
            {
                if ( resultMetaDataBean.getDisplay() == true )
                {
                    resultMetaDataBeanList.add( resultMetaDataBean );
                }
            }
            else
            {
                resultMetaDataBeanList.add( resultMetaDataBean );
            }
        }
        return resultMetaDataBeanList;
    }
}
